# -*- coding: UTF-8 -*-

import os
import services.base
import inspect

class Services:
    plugin_dir = "services"

    def __init__(self):
        self.modules = {}
        self.get_services()
        
    def get_services(self):
        d = os.path.join(os.path.dirname(__file__), self.plugin_dir)
        for fname in os.listdir(d):
            if fname.endswith (".py"):
                module_name = fname[: -3]
                if module_name != "base" and module_name != "__init__":
                    print "Load module %s" % module_name

                    package_obj = __import__(self.plugin_dir + "." +  module_name)
                    module_obj = getattr (package_obj, module_name)
                    for elem in dir(module_obj):
                        obj = getattr(module_obj, elem)
                        if inspect.isclass(obj):
                            if issubclass (obj, services.base.Core):
                                self.modules[obj.__label__] = obj
        return self.modules
